package academic.emailClient.control.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import academic.emailClient.control.MessageMapper;
import academic.emailClient.model.EmailClientModel;
import academic.emailClient.model.entities.Message;
import academic.emailClient.view.EmailClientViewImp;
import academic.emailClient.view.EmailClientViewInterface;

/**
 * class used to tell how to react to the save (to Sent) action
 * by checking if the data entered in the composed message are valid
 * and calling a method in the model to save the message in the model
 */
public class SaveToSentListener	implements ActionListener{
		EmailClientModel model;
		EmailClientViewInterface view;

		/**
		 * constructor
		 * @param view
		 * @param model
		 */
		public SaveToSentListener(EmailClientViewInterface view, EmailClientModel model){
		   this.view=view;
		   this.model=model;
	   
		}
		
		/**
		 * Handle Save To Sent Event
		 */
		@Override
		public void actionPerformed(ActionEvent arg0) {
		   if (view.validateMessageData()){
			   	  	Message message = MessageMapper.mapToMessage(view.getNewMessage("Saved To Sent"));
				    model.saveToSendMessage(message);
					view.updateMailBoxList(MessageMapper.mapToMessageViewList(model.getIboxMessages()));
							   }
			   
		}
		
}



